package com.maxatime.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.maxatime.dao.ExamGradeStudentRelationMapper;
import com.maxatime.dao.ExamStudentBasicInfoMapper;
import com.maxatime.pojo.entity.ExamGradeStudentRelation;
import com.maxatime.pojo.entity.ExamStudentBasicInfo;
import com.maxatime.service.Ssbkaoshi;
import com.maxatime.util.SerialNumberUtil;

@Service
public class SsbkaoshiImpl implements Ssbkaoshi{

	@Autowired
	ExamStudentBasicInfoMapper examStudentBasicInfoMapper;
	@Autowired
	ExamGradeStudentRelationMapper examGradeStudentRelationMapper;
	
	
	@Override
	public int insert(ExamStudentBasicInfo record) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	@Transactional
	public int insertSelective(ExamStudentBasicInfo record) {
		// TODO Auto-generated method stub
		Date d = new Date();
		ExamStudentBasicInfo examStudentBasicInfo = new ExamStudentBasicInfo();
		BeanUtils.copyProperties(record, examStudentBasicInfo);
		examStudentBasicInfo.setDeleteFlag("0");
		examStudentBasicInfo.setCreateTime(d);
		examStudentBasicInfo.setUpdateTime(d);
		String studentId1 = String.valueOf(SerialNumberUtil.getRandomNum());//随机数
		String studentId2 = String.valueOf(SerialNumberUtil.getRandomNum());//随机数
		String studentNum = String.valueOf(SerialNumberUtil.getRandomNum());//随机数
		examStudentBasicInfo.setStudentId(studentId1);
		examStudentBasicInfo.setStudentNum(studentNum);
		examStudentBasicInfoMapper.insertSelective(examStudentBasicInfo);
		
		ExamGradeStudentRelation examGradeStudentRelation = new ExamGradeStudentRelation();//第二个表
		examGradeStudentRelation.setDeleteFlag("0");
		examGradeStudentRelation.setCreateTime(d);
		examGradeStudentRelation.setUpdateTime(d);
		examGradeStudentRelation.setStudentId(studentId2);
		examGradeStudentRelation.setGradeGradeName(examStudentBasicInfo.getStudentName());
		
		examGradeStudentRelationMapper.insertSelective(examGradeStudentRelation);
		return 0;
	}

	@Override
	public ExamStudentBasicInfo selectByPrimaryKey(Integer pkId) {
		// TODO Auto-generated method stub
		return null;
	}
	//修改
	@Override
	public ExamStudentBasicInfo updateByPrimaryKeySelective(ExamStudentBasicInfo record) {
		// TODO Auto-generated method stub
		ExamStudentBasicInfo examStudentBasicInfo = new ExamStudentBasicInfo();
		BeanUtils.copyProperties(record, examStudentBasicInfo);
		
		return examStudentBasicInfoMapper.updateByPrimaryKeySelective(examStudentBasicInfo);
	}

	@Override
	public int updateByPrimaryKey(ExamStudentBasicInfo record) {
		// TODO Auto-generated method stub
		return 0;
	}
	//查询
	@Override
	public List<ExamStudentBasicInfo> listData(ExamStudentBasicInfo examStudentBasicInfo) {
		// TODO Auto-generated method stub
		List<ExamStudentBasicInfo> list = examStudentBasicInfoMapper.listData(examStudentBasicInfo);
		return list;
	}
	//反显
	@Override
	public ExamStudentBasicInfo findstudentId(String studentId) {
		// TODO Auto-generated method stub
		
		return examStudentBasicInfoMapper.findstudentId(studentId);
	}
	//删除
	@Override
	public int deleteByPrimaryKey(String studentId) {
		// TODO Auto-generated method stub
		examStudentBasicInfoMapper.deleteByPrimaryKey(studentId);
		examGradeStudentRelationMapper.deleteByPrimaryKey(studentId);
		return 0;
	}
	//bzt查询
	@Override
	public List<ExamStudentBasicInfo> listData2(ExamStudentBasicInfo examStudentBasicInfo) {
		// TODO Auto-generated method stub
		List<ExamStudentBasicInfo> list = examStudentBasicInfoMapper.listData2(examStudentBasicInfo);
		return list;
	}

}
